<template>
  <div class="chat-welcome-container">
    <div class="welcome-content">
      <!-- 欢迎图标 -->
      <div class="welcome-icon">
        <el-avatar :size="80" :src="aiAvatarUrl" />
      </div>
      
      <!-- 欢迎标题 -->
      <div class="welcome-title">
        <h2>欢迎使用 AI 智能助手</h2>
        <p>开始与AI对话，体验智能问答的魅力</p>
      </div>
      
      <!-- 功能介绍 -->
      <div class="feature-list">
        <div class="feature-item">
          <el-icon><ChatDotRound /></el-icon>
          <div class="feature-content">
            <h4>智能对话</h4>
            <p>支持多轮连续对话，AI能记住完整的聊天历史</p>
          </div>
        </div>
        
        <div class="feature-item">
          <el-icon><FolderOpened /></el-icon>
          <div class="feature-content">
            <h4>会话管理</h4>
            <p>创建多个独立会话，分类管理不同话题的对话</p>
          </div>
        </div>
        
        <div class="feature-item">
          <el-icon><Document /></el-icon>
          <div class="feature-content">
            <h4>内容丰富</h4>
            <p>支持文本、代码、markdown等多种内容格式</p>
          </div>
        </div>
        
        <div class="feature-item">
          <el-icon><Share /></el-icon>
          <div class="feature-content">
            <h4>便捷操作</h4>
            <p>一键复制回答，快速分享有用信息</p>
          </div>
        </div>
      </div>
      
      <!-- 快速开始 -->
      <div class="quick-start">
        <h3>快速开始</h3>
        <div class="start-actions">
          <el-button 
            type="primary" 
            size="large"
            @click="createNewChat"
            :loading="chatStore.isLoading"
          >
            <el-icon><Plus /></el-icon>
            创建新对话
          </el-button>
        </div>
        
        <!-- 示例问题 -->
        <div class="sample-questions">
          <p>你可以这样开始：</p>
          <div class="question-chips">
            <el-tag 
              v-for="question in sampleQuestions" 
              :key="question"
              class="question-chip"
              @click="handleSampleQuestion(question)"
              type="info"
              effect="plain"
            >
              {{ question }}
            </el-tag>
          </div>
        </div>
      </div>
      
      <!-- 使用提示 -->
      <div class="usage-tips">
        <el-alert
          title="使用提示"
          type="info"
          :closable="false"
          show-icon
        >
          <ul>
            <li>使用 <strong>Enter</strong> 键快速发送消息</li>
            <li>使用 <strong>Shift + Enter</strong> 进行换行</li>
            <li>点击消息旁的复制按钮可以复制AI回答</li>
            <li>左侧可以管理多个对话会话</li>
          </ul>
        </el-alert>
      </div>
    </div>
  </div>
</template>

<script setup>
/**
 * 聊天欢迎页面组件
 * 在没有选择会话时显示，提供功能介绍和快速开始选项
 */
import { useChatStore } from '@/stores/chat'
import { ElMessage } from 'element-plus'
import { ChatDotRound, FolderOpened, Document, Share, Plus } from '@element-plus/icons-vue'
import deepseekAvatar from '@/assets/deepseek-logo.png'

const chatStore = useChatStore()
const aiAvatarUrl = deepseekAvatar

// 示例问题
const sampleQuestions = [
  "你好，介绍一下自己吧",
  "帮我写一个Vue组件",
  "解释一下机器学习",
  "推荐一些学习资源",
  "今天天气怎么样？"
]

/**
 * 创建新的聊天会话
 */
const createNewChat = async () => {
  try {
    const response = await chatStore.createNewSession()
    if (response.success) {
      ElMessage.success('新会话创建成功')
    } else {
      ElMessage.error(response.message || '创建会话失败')
    }
  } catch (error) {
    console.error('创建会话失败:', error)
    ElMessage.error('创建会话失败，请重试')
  }
}

/**
 * 处理示例问题点击
 */
const handleSampleQuestion = async (question) => {
  try {
    // 先创建新会话
    const createResponse = await chatStore.createNewSession()
    if (!createResponse.success) {
      ElMessage.error('创建会话失败')
      return
    }
    
    // 发送示例问题
    const sendResponse = await chatStore.sendMessage(question)
    if (sendResponse.success) {
      ElMessage.success('问题已发送')
    } else {
      ElMessage.error('发送问题失败')
    }
  } catch (error) {
    console.error('处理示例问题失败:', error)
    ElMessage.error('操作失败，请重试')
  }
}
</script>

<style scoped>
.chat-welcome-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 40px 20px;
  overflow-y: auto;
}

.welcome-content {
  max-width: 600px;
  width: 100%;
  background-color: #ffffff;
  border-radius: 20px;
  padding: 40px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  text-align: center;
}

/* 欢迎图标 */
.welcome-icon {
  margin-bottom: 24px;
}

/* 欢迎标题 */
.welcome-title {
  margin-bottom: 40px;
}

.welcome-title h2 {
  margin: 0 0 12px 0;
  font-size: 28px;
  font-weight: 600;
  color: #303133;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-title p {
  margin: 0;
  font-size: 16px;
  color: #606266;
  line-height: 1.5;
}

/* 功能列表 */
.feature-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
  text-align: left;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.feature-item:hover {
  background-color: #e3f2fd;
  transform: translateY(-2px);
}

.feature-item .el-icon {
  font-size: 24px;
  color: #667eea;
  margin-right: 16px;
  margin-top: 2px;
  flex-shrink: 0;
}

.feature-content h4 {
  margin: 0 0 8px 0;
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.feature-content p {
  margin: 0;
  font-size: 14px;
  color: #606266;
  line-height: 1.5;
}

/* 快速开始 */
.quick-start {
  margin-bottom: 32px;
}

.quick-start h3 {
  margin: 0 0 20px 0;
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}

.start-actions {
  margin-bottom: 24px;
}

.start-actions .el-button {
  padding: 12px 24px;
  font-size: 16px;
  border-radius: 12px;
}

/* 示例问题 */
.sample-questions {
  text-align: center;
}

.sample-questions p {
  margin: 0 0 16px 0;
  font-size: 14px;
  color: #606266;
}

.question-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.question-chip {
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 20px;
  padding: 8px 16px;
}

.question-chip:hover {
  background-color: #667eea;
  color: white;
  border-color: #667eea;
}

/* 使用提示 */
.usage-tips {
  text-align: left;
}

.usage-tips :deep(.el-alert) {
  border-radius: 12px;
}

.usage-tips ul {
  margin: 8px 0 0 0;
  padding-left: 20px;
}

.usage-tips li {
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.usage-tips strong {
  color: #667eea;
  font-weight: 600;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .chat-welcome-container {
    padding: 20px 16px;
  }
  
  .welcome-content {
    padding: 24px 20px;
  }
  
  .welcome-title h2 {
    font-size: 24px;
  }
  
  .feature-list {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .feature-item {
    padding: 16px;
  }
  
  .question-chips {
    gap: 6px;
  }
  
  .question-chip {
    font-size: 13px;
    padding: 6px 12px;
  }
}

@media (max-width: 480px) {
  .welcome-content {
    padding: 20px 16px;
  }
  
  .welcome-title h2 {
    font-size: 22px;
  }
  
  .welcome-title p {
    font-size: 15px;
  }
  
  .feature-item {
    flex-direction: column;
    text-align: center;
  }
  
  .feature-item .el-icon {
    margin-right: 0;
    margin-bottom: 8px;
  }
}
</style> 